<template>
  <div>
    <el-row>
      <el-col>
        <header class="head">能力信息</header>
        <el-form label-width="100px">
          <el-form-item label="能力类型：">
            {{ selectDictLabel(fbOptions.protocolTypeList, fbOptions.flow.selectNode.data.apiType) }}
          </el-form-item>
          <el-form-item label="配置接口：">
            <el-button
              size="mini"
              type="primary"
              icon="el-icon-search"
              :disabled="isView"
              @click="visible = true"
              >搜索接口</el-button
            >
          </el-form-item>
          <el-form-item label="能力编码：">
            {{ formData.serviceCode || "" }}
          </el-form-item>
          <el-form-item label="能力名称：">
            {{ formData.serviceName || "" }}
          </el-form-item>
          <el-form-item label="能力版本：">
            {{ formData.serviceMasterVersion ? `V${formData.serviceMasterVersion}` : "" }}
          </el-form-item>
          <el-form-item label="请求路径：">
            {{ formData.mockUrl || "" }}
          </el-form-item>
          <el-form-item label="所属分类：">
            {{ formData.cateName || "" }}
          </el-form-item>
<!--          <el-form-item label="认证方式：">-->
<!--            <el-radio-group-->
<!--              class="radio-group"-->
<!--              :value="formData.targetAuthType"-->
<!--            >-->
<!--              <el-radio label="0">公开</el-radio>-->
<!--              <el-radio label="1">数字签名</el-radio>-->
<!--              <el-radio label="2">对程加密</el-radio>-->
<!--              <el-radio label="3">Token</el-radio>-->
<!--              <el-radio label="4">Bearer</el-radio>-->
<!--              <el-radio label="5">Basic</el-radio>-->
<!--            </el-radio-group>-->
<!--          </el-form-item>-->
        </el-form>
      </el-col>
    </el-row>
    <el-dialog
      width="1000px"
      v-el-drag-dialog
      append-to-body
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      v-model="visible"
      title="选择能力"
    >
      <step-xzapi :fbOptions="fbOptions" v-if="visible" @onChoose="onChoose" />
      <dialog-footer slot="footer" :showCancle="false" @ok="onOk" />
    </el-dialog>
  </div>
</template>

<script>
import {searchServiceById, selectById} from "@slc/api/slc/api";
import StepXzapi from "../step-fhbp/step-xzapi.vue";
export default {
  name: "custom-apiport",
  components: {
    StepXzapi,
  },
  props: {
    fbOptions: {
      type: Object,
      default: () => {
      }
    },
  },
  data() {
    return {
      visible: false,
      chooseInfo: {},
    };
  },
  computed: {
    formData() {
      return this.fbOptions.flow.moreNodeInfo[this.fbOptions.flow.currentNodeId] || {};
    },
    isView() {
      return (
        this.fbOptions.operationType === "view"
      );
    },
  },
  methods: {
    onChoose(val) {
      this.chooseInfo = val;
    },
    onOk() {
      const { serviceId } = this.chooseInfo;
      searchServiceById(serviceId).then((res) => {
        if (res.code === "200") {
          this.fbOptions.flow.moreNodeInfo = {
            ...this.fbOptions.flow.moreNodeInfo,
            [this.fbOptions.flow.currentNodeId]: res.data || {},
          }
          this.visible = false;
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.head {
  height: 40px;
  text-align: center;
  line-height: 40px;
  color: #333;
  font-weight: bold;
  font-size: 14px;
  background-color: #ccc;
  margin-bottom: 16px;
}
.el-form-item {
  margin-bottom: 0px;
}
.radio-group {
  .el-radio {
    margin-top: 10px;
  }
}
</style>
